---@class Battle.EnemyLordAi : Battle.AiBase
local EnemyLordAi = Battle.CreateClass("BossAi",Battle.AiBase)
Battle.EnemyLordAi = EnemyLordAi

---@param actor Battle.Entity
local function SearchTarget(actor)
    local list = Battle.ActorManager.GetActorList()
    local minDis = 10000000000
    local target
    local enemyCamp = Battle.BattleUtil.GetEnemyCamp(actor.camp)
    local searchRadiusSqr = actor.searchRadius * actor.searchRadius
    for k,v in pairs(list) do
        if v.camp == enemyCamp and actor:CanTarget(v) then
            local dis = Battle.BattleUtil.DistanceSqr(actor.pos,v.pos)
            if dis < searchRadiusSqr and dis < minDis then
                minDis = dis
                target = v
            end
        end
    end
    return target
end
---@param actor Battle.Entity
local function GetSkill(actor)
    return actor.skillSystem:GetSkill1Id()
end
function EnemyLordAi:OnCreate()
    local Tree = Battle.AiTree
    local Decorator = Battle.AiDecoratorType
    local Condition = Battle.AiConditionType
    local Action = Battle.AiActionType

    Tree.CLEAR()
    --循环
    Tree.BEGIN_DECORATOR(Decorator.Repeater,-1)
        Tree.BEGIN_SELECTOR()
            --手动释放技能
    --[[--]]Tree.BEGIN_CONDITION(Condition.Trigger,"hand_skill",true)
    --[[    --]]Tree.BEGIN_SEQUENCE()
    --[[        --]]Tree.ADD_ACTION(Action.DoSkill,GetSkill)
    --[[        --]]Tree.ADD_ACTION(Action.TriggerSet,"hand_skill",false)
    --[[    --]]Tree.END_SEQUENCE()
    --[[--]]Tree.END_CONDITION()
            --受击表现
    --[[--]]Tree.BEGIN_CONDITION(Condition.Trigger,"hit",true)
    --[[    --]]Tree.BEGIN_SEQUENCE()
    --[[        --]]Tree.ADD_ACTION(Action.EnterHitAction)
    --[[        --]]Tree.ADD_ACTION(Action.TriggerSet,"hit",false)
    --[[    --]]Tree.END_SEQUENCE()
    --[[--]]Tree.END_CONDITION()
    --有目标 攻击目标
    --[[--]]Tree.BEGIN_CONDITION(Condition.HasTarget)
    --[[    --]]Tree.BEGIN_SELECTOR()

    --[[        --]]Tree.BEGIN_CONDITION(Condition.CanUseSkill,self.actor.skillSystem:GetNormalSkillId())
    --[[            --]]Tree.BEGIN_CONDITION(Condition.InSkillRange,self.actor.skillSystem:GetNormalSkillId())--在技能范围类
    --[[                --]]Tree.ADD_ACTION(Action.DoSkill,self.actor.skillSystem:GetNormalSkillId())
    --[[            --]]Tree.END_CONDITION()
    --[[        --]]Tree.END_CONDITION()
    --[[    --]]Tree.END_SELECTOR()
    --[[--]]Tree.END_CONDITION()
    --[[--]]Tree.ADD_ACTION(Action.SetSearchTarget,SearchTarget)--搜索最近敌人
        Tree.END_SELECTOR()
    Tree.END_DECORATOR()

    self.tree = Tree.New(Tree.GET_ROOT(),self.actor)
end
